package org.springframework.resource;

import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.ResourceLoader;

import java.io.IOException;
import java.io.InputStream;

/**
 * @Author: T-jack
 * @Date: 2023-12-20-10:50
 * @Description: spring 资源管理对象
 */
public class Resource {
	public String getResource(){
		//创建ResourceLoader
		ResourceLoader resourceLoader = new DefaultResourceLoader();
		//获取资源
		org.springframework.core.io.Resource resource = resourceLoader.getResource("http://www.baidu.com");
		String s="";
		try {
			InputStream inputStream = resource.getInputStream();
			byte[] bytes = new byte[1024];

			while (inputStream.read(bytes) != -1) {
				s += new String(bytes);
			}
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		return s;
	}

}
